
package nccloud.impl.arap.rgcb.action;

import nc.bs.pub.action.N_RGCB_APPROVE;
import nc.vo.arap.manualcost.AggManualCostVO;
import nc.vo.pubapp.pattern.exception.ExceptionUtils;
import nc.bs.ml.NCLangResOnserver;
import nc.impl.pubapp.pattern.rule.processer.AroundProcesser;
import nc.vo.pubapp.pattern.log.TimeLog;
import nccloud.bs.arap.rgcb.maintain.rule.audit.CheckEnableAuditRule;
import nccloud.bs.arap.rgcb.plugin.ActionPlugInPoint;
import nc.impl.pubapp.pattern.data.bill.BillQuery;

@SuppressWarnings("rawtypes")
public class ApproveAction {
        public AggManualCostVO[] approve(N_RGCB_APPROVE script) {
        AggManualCostVO[] ret = null;

                try {
                        Object[] inCurObject = script.getPfParameterVO().m_preValueVos;
                        if (inCurObject == null) {
                                ExceptionUtils.wrappBusinessException(
                                                NCLangResOnserver.getInstance().getStrByID("4009001_0", "04009001-0064"));
                                return null;
                        }

            AggManualCostVO[] inCurVOs = new AggManualCostVO[inCurObject.length];
                        int len = inCurObject.length;

                        for (int i = 0; i < len; ++i) {
                                inCurVOs[i] = (AggManualCostVO) inCurObject[i];
                        }

                        AroundProcesser<AggManualCostVO> processer = new AroundProcesser(ActionPlugInPoint.ApproveAction);
                        processer.addBeforeRule(new CheckEnableAuditRule());
                        TimeLog.logStart();
                        processer.before(inCurVOs);
                        TimeLog.info("调用审批流前执行业务规则");
                        script.procFlowBacth(script.getPfParameterVO());
                        TimeLog.logStart();
                        processer.after(inCurVOs);
                        TimeLog.info("调用审批流后执行业务规则");
                        ret = this.queryNewVO(inCurVOs);
                } catch (Exception var7) {
                        ExceptionUtils.wrappException(var7);
                }

                return ret;
        }

    @SuppressWarnings("unchecked")
        private AggManualCostVO[] queryNewVO(AggManualCostVO[] inCurVOs) {
                int len = inCurVOs.length;
                String[] ids = new String[len];

                for (int i = 0; i < len; ++i) {
                        ids[i] = inCurVOs[i].getPrimaryKey();
                }

                BillQuery<AggManualCostVO> query = new BillQuery(AggManualCostVO.class);
        AggManualCostVO[] bills = (AggManualCostVO[]) query.query(ids);
                return bills;
        }
}
